﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using BuyTicket.Models;
using BuyTicket.Service;

namespace BuyTicket.Views
{
    /// <summary>
    /// SubmitView.xaml 的交互逻辑
    /// </summary>
    public partial class SubmitView : UserControl
    {
        public SubmitView()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            SubmitArgs submitArgs = Application.Current.Properties["SubmitArgs"] as SubmitArgs;
            if (submitArgs != null)
            {
                txtTicketInfo.Text = submitArgs.TicketInfo;
                myTicketInfo.ItemsSource = Global.MyTicketArgs.Persons;
                myTicketInfo.DataContext = submitArgs;

                richCookies.AppendText(BuyTicketService.Cookies);
            }
        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        void Async(Func<object> func, Action<object> completed)
        {
            myError.Visibility = Visibility.Visible;
            mySubmit.IsEnabled = false;
            using (BackgroundWorker worker = new BackgroundWorker())
            {
                worker.DoWork += (sender, e) =>
                {
                    e.Result = func();
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    completed(e.Result);
                    myError.Visibility = Visibility.Collapsed;
                    mySubmit.IsEnabled = true;
                };
                worker.RunWorkerAsync();
            }
        }

        
    }
}
